package com.wavehi.producer;

import com.rabbitmq.client.Channel;
import com.sun.jdi.Value;
import com.wavehi.util.RabbitMQFactoryUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;
import java.util.function.BiConsumer;

/**
 * @Description 生产者 演示主题交换机的使用
 * @Author WaveHi
 * @Date 27/12/2021 下午 7:40
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */
public class Producer_03 {
    //交换机名词
    private static final String EXCHANGE_NAME = "topic_exchange";
    public static void main(String[] args) throws Exception {
        //1.获取连接信道
        Channel channel = RabbitMQFactoryUtils.getChannel();
        //2.准备消息
        HashMap<String, String> messages = new HashMap<>();
        messages.put("quick.orange.fox", "被队列 Q1 接收到");
        messages.put("lazy.brown.fox", "被队列 Q2 接收到");
        messages.put("lazy.pink.rabbit", "虽然满足两个绑定但只被队列 Q2 接收一次");
        messages.put("quick.brown.fox", "不匹配任何绑定不会被任何队列接收到会被丢弃");
        //3.发送消息
        messages.forEach((key, value) -> {
            try {
                channel.basicPublish(EXCHANGE_NAME, key, null,
                        value.getBytes("UTF-8"));
                System.out.printf("Send message '%s'!\n", value);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }
}
